import * as roleApi from '@/api/role'

const state = {
  roleList: [],
  roleDetail: {
    roleIds: []
  }
}

const mutations = {
  SET_ROLE_LIST(state, newValue) {
    state.roleList = newValue
  },
  SET_ROLE_DETAIL(state, newValue) {
    state.roleDetail = newValue
  }
}

const actions = {
  async updateRoleList({ commit }) {
    const res = await roleApi.getRoleList()
    commit('SET_ROLE_LIST', res)
  },
  async updateRoleDetail({ commit }, id) {
    const res = await roleApi.getRoleDetail(id)
    commit('SET_ROLE_DETAIL', res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
